<?php

defined('SYSPATH') or die('No direct script access.');

class Controller_Helper_Message {

    private static $_inst = null;
    private $errors = array();
    private $success = array();
    private $warning = array();
    private $data = array();
    private $payment = null;

    /**
     * Call this method to get singleton
     *
     * @return Model_Category
     */
    public static function get_instance()
    {
        if (self::$_inst === null)
        {
            self::$_inst = new Controller_Helper_Message;
        }
        return self::$_inst;
    }

    public function set_error($key, $file = null)
    {
        $session = Session::instance();
        if ($file != null)
        {
            $this->errors[] = Kohana::message($file, $key);
        }
        else
        {
            $this->errors[] = $key;
        }
        $session->set('errors', $this->errors);
    }

    public function get_error()
    {
        $session = Session::instance();
        $this->errors = $session->get('errors');
        return $this->errors;
    }

    public function set_success($key, $file = null)
    {
        $session = Session::instance();
        if ($file != null)
        {
            $this->success[] = Kohana::message($file, $key);
        }
        else
        {
            $this->success[] = $key;
        }
        $session->set('success', $this->success);
    }

    public function get_success()
    {
        $session = Session::instance();
        $this->success = $session->get('success');
        return $this->success;
    }

    public function set_warning($key, $file = null)
    {
        $session = Session::instance();
        if ($file != null)
        {
            $this->warning[] = Kohana::message($file, $key);
        }
        else
        {
            $this->warning[] = $key;
        }
        $session->set('warning', $this->warning);
    }

    public function get_warning()
    {
        $session = Session::instance();
        $this->warning = $session->get('warning');
        return $this->warning;
    }

    public function set_data($key, $value)
    {
        $session = Session::instance();

        $this->data[$key] = $value;

        $session->set('data', $this->data);
    }

    public function get_data()
    {
        $session = Session::instance();
        $this->data = $session->get('data');
        return $this->data;
    }

    public function set_payment($value)
    {
        $session = Session::instance();

        $this->payment = $value;

        $session->set('payment', $this->payment);
    }

    public function get_payment()
    {
        $session = Session::instance();
        $this->payment = $session->get('payment');
        return $this->payment;
    }

    public function reset()
    {
        $session = Session::instance();
        $session->delete('errors');
        $session->delete('success');
        $session->delete('warning');
        $session->delete('data');
        $this->errors = array();
    }

}

?>
